using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Base
{
    public class Point : MonoBehaviour
    {
        MeshFilter meshFilter;
        MeshRenderer meshRenderer;
        Mesh mesh;

        [SerializeField]
        Material mat;

        [SerializeField]
        Vector3 mPos;

        [SerializeField]
        float mPointSize = 4;

        int[] indices = new int[] {0,1,2,0,2,3 };
        Vector3[] vertices = new Vector3[4];
        // Start is called before the first frame update
        void Start()
        {
            meshFilter = GetComponent<MeshFilter>();
            meshRenderer = GetComponent<MeshRenderer>();
            mesh = meshFilter.mesh = new Mesh();

            float half = mPointSize / 2;
            vertices[0] = new Vector3(mPos.x - half,mPos.y + half,mPos.z);
            vertices[1] = new Vector3(mPos.x + half, mPos.y + half, mPos.z);
            vertices[2] = new Vector3(mPos.x + half, mPos.y - half, mPos.z);
            vertices[3] = new Vector3(mPos.x - half, mPos.y - half, mPos.z);
            mesh.vertices = vertices;
            mesh.triangles = indices;
            meshRenderer.sharedMaterial = mat;
        }

        // Update is called once per frame
        void Update()
        {
            float half = mPointSize / 2;
            vertices[0] = new Vector3(mPos.x - half, mPos.y + half, mPos.z);
            vertices[1] = new Vector3(mPos.x + half, mPos.y + half, mPos.z);
            vertices[2] = new Vector3(mPos.x + half, mPos.y - half, mPos.z);
            vertices[3] = new Vector3(mPos.x - half, mPos.y - half, mPos.z);
            mesh.vertices = vertices;
        }
    }
}
